# CMake 最低版本号要求
cmake_minimum_required(VERSION 3.20)

# 定义变量
# 可以为一个值，也可以为多个值
set(VAR1 on)
set(VAR2 2;GREATER;1) #和set(VAR2 2 GREATER 1)等价
set(VAR3 1 GREATER 2)
set(VAR4 1)

# 引用变量
message(STATUS "this is a varibale 1 " ${VAR1})
message(STATUS "this is a varibale 2 " ${VAR2})
message(STATUS "this is a varibale 3 ${VAR2}")
message(STATUS "this is a varibale 4 ${VAR${VAR4}}")    #实际上是输出${VAR1}
IF(VAR)
    message(STATUS "VAR IS tru 1 " ${VAR})
ENDIF(VAR)
IF(${VAR2}) #IF语句会先将${VAR1} 替换成 2 GREATER 1(和2;GREATER;1等价)，而这是一个为true的表达式
    message(STATUS "VAR IS tru 2 ${VAR2}")
ENDIF()
IF(${VAR3}) #IF语句会先将${VAR3} 替换成 1 GREATER 2 而这是一个为false的表达式
    message(STATUS "VAR IS tru 3 ${VAR3}")
ENDIF()
IF(VAR3)    #VAR3 本身为1 GREATER 2 为true
    message(STATUS "VAR IS tru 4 ${VAR3}")
ENDIF()
foreach(arg VAR3)   #arg在值VAR3中循环
    message(STATUS "VAR IS tru 5 ${arg}")
endforeach()
foreach(arg ${VAR3})    #foreach语句先将${VAR3}替换为1 GREATER 2，所以实际上可循环的值为1、GREATER、2
    message(STATUS "VAR IS tru 6 ${arg}")
endforeach()
foreach(arg IN LISTS VAR3)  #跟if语句一样，会把VAR3当变量处理，所以实际上可循环的值为1、GREATER、2
    message(STATUS "VAR IS tru 7 ${arg}")
endforeach()
foreach(arg IN LISTS ${VAR3}) #跟if语句一样，先将${VAR3}先进行替换，替换后的变量并没有定义，所以不进入此循环
    message(STATUS "VAR IS tru 8 ${arg}")
endforeach()
# 引用环境变量
message(STATUS "ENV IS tru " $ENV{CMAKE_INCLUDE_PATH})


##执行如下
# export CMAKE_INCLUDE_PATH=/usr/local
# cmake -P setvar.cmake